﻿using AutoMapper;
using banyuetan_2_0.AuthHelper.OverWrite;
using banyuetan_2_0.Common.Enum;
using banyuetan_2_0.Controllers;
using banyuetan_2_0.Extensions.ExpressionTool;
using banyuetan_2_0.IServices;
using banyuetan_2_0.Model;
using banyuetan_2_0.Model.Models;
using banyuetan_2_0.Model.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace banyuetan_2_0.Api.Controllers
{
    [Produces("application/json")]
    [Route("api/[controller]")]
    [ApiController]
    public class ArticleController : BaseApiCpntroller
    {
        private readonly ISysUserInfoServices _sysUserInfoServices;
        private readonly ICategoryService _categoryService;
        private readonly IArticleService _articleservice;
        private readonly ICategoryAndArticleService _categoryAndArticleService;
        private readonly IMapper mapper;

        public ArticleController(ISysUserInfoServices sysUserInfoServices, ICategoryService categoryService, IArticleService articleservice, ICategoryAndArticleService categoryAndArticleService, IMapper mapper)
        {
            _sysUserInfoServices = sysUserInfoServices;
            _categoryService = categoryService;
            _articleservice = articleservice;
            _categoryAndArticleService = categoryAndArticleService;
            this.mapper = mapper;
        }

        #region Get
        /// <summary>
        /// 关键字搜索并且分页拿到包含指定分类、新闻状态的文章，默认keyword为""，默认cId为0，则表示要获取到所有文章，默认state=all,表示要获取所有新闻状态的文章,默认以更新时间进行降序排列
        /// </summary>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<MessageModel<PageModel<ArticleViewModel>>> GetByKeywordPagedAsync([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 10, [FromQuery] string keyword = "",[FromQuery]string state="all",[FromQuery]int cId=0)
        {
            string strOrderByFileds = "aUpdateTime desc";
            //首先应该判断是否cId=0
            if (cId!=0)//如果不为0，就通过ArticleToCategory查询
            {
                //1.先找到ArticleToCategory集合
                var categoryAndArticles = await _categoryAndArticleService.Query(ca => ca.cId == cId);
                //2.解析出对应的aid集合
                List<object> ids = new List<object>();
                //object[] ids = new object[10];
                foreach (var item in categoryAndArticles)
                {
                    ids.Add(item.aId);                  
                }
                //3.拿到所有符合条件的Article集合
                var articles = await _articleservice.QueryByIDs(ids.ToArray());
                //4.根据条件筛选内容
                var predicate = PredicateBuilder.GetTrue<Article>();
                predicate = predicate.And(c => c.aIsDeleted == false);
                //判断搜索关键字
                if (string.IsNullOrEmpty(keyword) || string.IsNullOrWhiteSpace(keyword))
                {
                    keyword = "";
                }

                if (keyword != "")
                {
                    predicate = predicate.And(c => c.aTitle.Contains(keyword) || c.aDescribe.Contains(keyword) || c.aContent.Contains(keyword));
                }
                //判断文章状态关键字
                switch (state.ToLower())
                {
                    case "draft": predicate = predicate.And(c => c.aStatus == Status.Draft); break;
                    case "pendingreview": predicate = predicate.And(c => c.aStatus == Status.PendingReview); break;
                    case "firstpass": predicate = predicate.And(c => c.aStatus == Status.FirstPass); break;
                    case "secondpass": predicate = predicate.And(c => c.aStatus == Status.SecondPass); break;
                    case "finalpass": predicate = predicate.And(c => c.aStatus == Status.FinalPass); break;
                    case "reject": predicate = predicate.And(c => c.aStatus == Status.Reject); break;
                    default:
                        break;
                }
                var result = articles.Where(predicate.Compile()).OrderByDescending(a=>a.aUpdateTime);
                //5.封装分页
                var totalCount = result.Count();
                var pageCount = totalCount / pageSize + 1;
                var pageResult = result.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                return SuccessPage<ArticleViewModel>(pageIndex, totalCount, mapper.Map<List<ArticleViewModel>>(pageResult), pageCount);
            }
            else //如果为0，则根据条件在Article中筛选内容
            {
                var predicate = PredicateBuilder.GetTrue<Article>();
                predicate=predicate.And(c => c.aIsDeleted == false);
                //判断搜索关键字
                if (string.IsNullOrEmpty(keyword) || string.IsNullOrWhiteSpace(keyword))
                {
                    keyword = "";
                }

                if (keyword != "")
                {
                    predicate=predicate.And(c => c.aTitle.Contains(keyword) || c.aDescribe.Contains(keyword) || c.aContent.Contains(keyword));
                }
                //判断文章状态关键字
                switch (state.ToLower())
                {
                    case "draft": predicate=predicate.And(c => c.aStatus == Status.Draft);break;
                    case "pendingreview": predicate=predicate.And(c => c.aStatus == Status.PendingReview); break;
                    case "firstpass": predicate=predicate.And(c => c.aStatus == Status.FirstPass); break;
                    case "secondpass": predicate=predicate.And(c => c.aStatus == Status.SecondPass); break;
                    case "finalpass": predicate=predicate.And(c => c.aStatus == Status.FinalPass); break;
                    case "reject": predicate=predicate.And(c => c.aStatus == Status.Reject); break;
                    default:
                        break;
                }
                var result = await _articleservice.QueryPage(predicate, pageIndex, pageSize, strOrderByFileds);
                return SuccessPage<ArticleViewModel>(pageIndex, result.dataCount, mapper.Map<List<ArticleViewModel>>(result.data), result.pageCount);
            }

            


            //var result = await _categoryService.QueryPage(expression, pageIndex, pageSize);
            //var pageModel= new PageModel<CategoryViewModel>() { data = mapper.Map<List<CategoryViewModel>>(result.data), dataCount = result.dataCount, page = result.page, pageCount = result.pageCount, PageSize = result.PageSize };
            //return SuccessPage<CategoryViewModel>(pageIndex, result.dataCount, data, result.pageCount);
        }
        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <param name="aId"></param>
        /// <returns></returns>
        [HttpGet("{aId}")]
        public async Task<MessageModel<ArticleViewModel>> GetSingle(int aId)
        {
            var data = new MessageModel<ArticleViewModel>();
            var result = await _articleservice.QueryById(aId);
            if (result!=null)
            {
                data.success = true;
                data.status = 200;
                data.response = mapper.Map<ArticleViewModel>(result);
            }
            return data;
        }

        /// <summary>
        /// 获取单个文章Id获取到所有相关联的Cagegory集合
        /// </summary>
        /// <param name="aId"></param>
        /// <returns></returns>
        [HttpGet("{aId}/categories")]
        public async Task<MessageModel<List<CategoryViewModel>>> GetCagegoriesByArticleId(int aId)
        {
            var data = new MessageModel<List<CategoryViewModel>>();
            var categoryAndArticles = await _categoryAndArticleService.Query(caa=>caa.aId==aId);
            //2023年7月17日21:08:42 目前使用笨办法，一级一级手动查,高级方法为Including，在查Article对象时就带出其相关的所有内容
            var ids=categoryAndArticles.Select(caa=>caa.cId).ToList();
            var categories=await _categoryService.Query(cs=>ids.Contains(cs.cID));
            if (categories != null)
            {
                data.success = true;
                data.status = 200;
                data.response = mapper.Map<List<CategoryViewModel>>(categories);
            }
            return data;
        }

        #endregion
        /// <summary>
        /// 生成Article
        /// </summary>
        /// <param name="articleViewModelForCreate"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<Article>> Post(ArticleViewModelForCreate articleViewModelForCreate)
        {
            MessageModel<Article> messageModel = new MessageModel<Article>();
            //开启事务处理
            var articleInTable = new Article();
            var _db = _articleservice.Db();
            try
            {
                _db.Ado.BeginTran();
                //1.生成Article主体
                var article = mapper.Map<Article>(articleViewModelForCreate);
                //更新编辑信息：拿到当前操作用户的id
                var token = Request.Headers["Authorization"];
                var tokenModel = JwtHelper.SerializeJwt(token);
                if (tokenModel != null && tokenModel.Uid > 0)
                {
                    var userinfo = await _sysUserInfoServices.QueryById(tokenModel.Uid);
                    if (userinfo != null)
                    {
                        article.aEditorId = userinfo.uID;
                    }
                }
                //await _articleservice.Add(article);
                articleInTable = await _db.Insertable<Article>(article).ExecuteReturnEntityAsync();
                //_db.Ado.CommitTran();
                //articleInTable = /*(await _articleservice.Query(a => a.aTitle == article.aTitle && a.aContent == article.aContent)).FirstOrDefault();*/
                //_db.Queryable<Article>().Where(a => a.aTitle == article.aTitle && a.aContent == article.aContent).First();

                var articleId = articleInTable.aId;
                //2.添加Category
                //添加前先判断是否有重复
                //_db.Ado.BeginTran();
                var categories = articleViewModelForCreate.aExtraCategoryId.ToList();
                if (!categories.Contains(articleViewModelForCreate.aCategoryId))
                {
                    categories.Add(articleViewModelForCreate.aCategoryId);
                }
                categories = categories.Distinct().ToList();
                var categoryAndArticle = new List<CategoryAndArticle>();
                foreach (var item in categories)
                {
                    var obj = new CategoryAndArticle() { aId = articleId, cId = item };
                    categoryAndArticle.Add(obj);
                }
                _db.Insertable<CategoryAndArticle>(categoryAndArticle).ExecuteCommand();
                //3.添加Source
                var sources = articleViewModelForCreate.aRelationPic.ToList();
                sources = sources.Distinct().ToList();
                var articleAndSource = new List<ArticleAndSource>();
                foreach (var item in sources)
                {
                    var obj = new ArticleAndSource() { aId = articleId, sId = item };
                    articleAndSource.Add(obj);
                }
                _db.Insertable<ArticleAndSource>(articleAndSource).ExecuteCommand();
                _db.Ado.CommitTran();
                messageModel.response = articleInTable;
                messageModel.success = true;
                
            }
            catch (Exception ex)
            {
                _db.Ado.RollbackTran();
                //await _articleservice.DeleteById(articleInTable.aId);//如果操作失败，连article一并删除了
                messageModel.msg = ex.Message;
            }
            return messageModel;

        }

        /// <summary>
        /// 根据ID删除指定文章（假删除）
        /// </summary>
        /// <param name="aId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<bool>> Delete(int aId)
        {
            MessageModel<bool> messageModel = new MessageModel<bool>();
            //找到指定对象，仅删除文章即可
            var result = await _articleservice.QueryById(aId);
            if (result==null)
            {
                messageModel.response = false;
                //messageModel.success = false;
                messageModel.msg = "未找到指定对象，删除失败";
                return messageModel;
            }
            result.aIsDeleted = true;
            var re= await _articleservice.Update(result);
            if (re)
            {
                messageModel.response = true;
                messageModel.success = true;
                messageModel.msg = "操作成功";
            }
            else
            {
                messageModel.response = false;
                //messageModel.success = false;
                messageModel.msg = "服务器错误，删除失败";
            }
            return messageModel;
        }

        /// <summary>
        /// 根据ID删除指定文章（假删除）
        /// </summary>
        /// <param name="aIds"></param>
        /// <returns></returns>
        [HttpDelete("multiple")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<bool>> DeleteMultiple([FromBody]int[] aIds)
        {
            MessageModel<bool> messageModel = new MessageModel<bool>();
            //找到指定对象，仅删除文章即可
            var length = aIds.Length;
            var objIds = new object[length];
            for (int i = 0; i < length; i++)
            {
                objIds[i] = aIds[i];
            }
            //objIds.AddRange((IEnumerable<object>)aIds.AsEnumerable());

            var result = await _articleservice.QueryByIDs(objIds);
            //开启事务
            var _db = _articleservice.Db();
            try
            {
                _db.Ado.BeginTran();
                foreach (var item in result)
                {
                    if (item != null)
                    {
                        item.aIsDeleted = true;
                        _db.Updateable<Article>(item).ExecuteCommand();
                    }
                }
                _db.Ado.CommitTran();
                messageModel.response = true;
                messageModel.success = true;
                messageModel.msg = "操作成功";
                return messageModel;
            }
            catch (Exception ex)
            {
                _db.Ado.RollbackTran();
                messageModel.response = false;
                //messageModel.success = false;
                messageModel.msg = ex.Message;
                return messageModel;
            }
        }

        #region Update

        /// <summary>
        /// 修改文章
        /// </summary>
        /// <param name="articleViewModelForCreate"></param>
        /// <returns></returns>
        [HttpPut]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> Update(ArticleViewModelForCreate articleViewModelForCreate)
        {
            MessageModel<ArticleViewModel> messageModel = new MessageModel<ArticleViewModel>();
            var _db = _articleservice.Db();
            try
            {
                var article = mapper.Map<Article>(articleViewModelForCreate);
                _db.Ado.BeginTran(); //事务开始
                //1.修改新闻本体
                await _db.Updateable<Article>(article).ExecuteCommandAsync();

                //2.修改ArticleAndCategory:找到原来的老的，全部删除，再添加新的
                //删除旧的
                var categoryAndArticles = _db.Queryable<CategoryAndArticle>().Where(ca => ca.aId == article.aId).Select(ca => ca.caId).ToList();
                _db.Deleteable<CategoryAndArticle>(categoryAndArticles).ExecuteCommand();
                //添加新的
                var categories = articleViewModelForCreate.aExtraCategoryId.ToList();
                if (!categories.Contains(articleViewModelForCreate.aCategoryId))
                {
                    categories.Add(articleViewModelForCreate.aCategoryId);
                }
                categories = categories.Distinct().OrderBy(c=>c).ToList();
                var categoryAndArticle = new List<CategoryAndArticle>();
                foreach (var item in categories)
                {
                    var obj = new CategoryAndArticle() { aId = article.aId, cId = item };
                    categoryAndArticle.Add(obj);
                }
                _db.Insertable<CategoryAndArticle>(categoryAndArticle).ExecuteCommand();

                //3.修改ArticleAndSource
                //删除旧的
                var articleAndSources = _db.Queryable<ArticleAndSource>().Where(ca => ca.aId == article.aId).Select(ca => ca.asId).ToList();
                _db.Deleteable<ArticleAndSource>(articleAndSources).ExecuteCommand();
                //添加新的
                var sources = articleViewModelForCreate.aRelationPic.ToList();
                if (!categories.Contains(articleViewModelForCreate.aTitlePicId))
                {
                    categories.Add(articleViewModelForCreate.aTitlePicId);
                }
                sources = sources.Distinct().OrderBy(c => c).ToList();
                var articleAndSource = new List<ArticleAndSource>();
                foreach (var item in sources)
                {
                    var obj = new ArticleAndSource() { aId = article.aId, sId = item };
                    articleAndSource.Add(obj);
                }
                _db.Insertable<ArticleAndSource>(articleAndSource).ExecuteCommand();
                _db.Ado.CommitTran();//事务结束

                messageModel.response = mapper.Map<ArticleViewModel>(article);
                messageModel.success = true;
                messageModel.msg = "操作成功";
            }
            catch (Exception ex)
            {
                _db.Ado.RollbackTran();
                messageModel.msg = ex.Message;
            }
            return messageModel;
        }

        //================================所有的修改文章状态操作都不能偷懒，因为要指定操作每一个函数的权限=======================

        /// <summary>
        /// 修改文章至指定退稿
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/reject")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToReject([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();
            
            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus==Status.Reject) {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.Reject;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至指定终审通过
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/finalpass")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToFinalPass([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();

            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus == Status.FirstPass)
            {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.FinalPass;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至指定二审通过
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/secondpass")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToSecondPass([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();

            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus == Status.SecondPass)
            {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.SecondPass;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至指定初审通过
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/firstpass")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToFirstPass([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();

            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus == Status.FirstPass)
            {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.FirstPass;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至指定待审核
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/pendingreview")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToPendingReview([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();

            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus == Status.PendingReview)
            {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.PendingReview;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至指定为草稿
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("status/draft")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatusToDraft([FromQuery] int id)
        {
            var messageModel = new MessageModel<ArticleViewModel>();

            var target = await _articleservice.QueryById(id);
            if (target == null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //判断是否为原来的新闻状态
            if (target.aStatus == Status.Draft)
            {
                messageModel.msg = "与原来的状态相同，没有操作必要！";
                return messageModel;
            }
            //操作内容
            target.aStatus = Status.Draft;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }

        }

        /// <summary>
        /// 修改文章至任意指定状态，最高的操作权限
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        [HttpPut("status")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> ChangeStatus([FromQuery]int id,[FromQuery]int status = 0)
        {
            var messageModel = new MessageModel<ArticleViewModel>();
            //验证参数及是否有指定对象
            if (status>5||status<0)
            {
                messageModel.msg = "参数验证失败，不允许使用非约定的文章状态！";
                return messageModel;
            }
            var target = await _articleservice.QueryById(id);
            if (target==null)
            {
                messageModel.msg = "未找到指定对象，操作失败！";
                return messageModel;
            }
            //操作内容
            target.aStatus = (Status)status;
            var result = await _articleservice.Update(target);
            if (result)
            {
                messageModel.success = result;
                messageModel.msg = "操作成功!";
                return messageModel;
            }
            else
            {
                messageModel.msg = "服务器错误，操作成败！";
                return messageModel;
            }
           
        }


        /// <summary>
        /// 添加文章到指定分类
        /// </summary>
        /// <param name="id"></param>
        /// <param name="categoryid"></param>
        /// <returns></returns>
        [HttpPut("addToCategory")]
        [Authorize(Permissions.Name)]
        public async Task<MessageModel<ArticleViewModel>> AddToCategory([FromQuery] int id, [FromQuery] int categoryid)
        {
            var messageModel = new MessageModel<ArticleViewModel>();
            //查找指定目标
            //var target = await _articleservice.QueryById(id);
            var categoryAndArticle = await _categoryAndArticleService.Query(cad => cad.aId == id);
            var targetList=new List<int>();
            foreach (var category in categoryAndArticle) { targetList.Add(category.cId); }
            //判断是否已经在此分类中
            if (targetList.Contains(categoryid))
            {
                messageModel.msg = "已经在此分类中，操作失败！";
                return messageModel;
            }
            else
            {
                //未在分类中，添加关系
                var newCategoryAndArticle = new CategoryAndArticle() { aId = id, cId = categoryid };
                var result = await _categoryAndArticleService.Add(newCategoryAndArticle);
                if (result>0)
                {
                    messageModel.success = true;
                    messageModel.msg = "操作成功!";
                    return messageModel;
                }
                else
                {
                    messageModel.msg = "服务器错误，操作成败！";
                    return messageModel;
                }
            }
            
         

        }
        #endregion
    }


}
